import json
import os
from flask import Blueprint, make_response

from api.config import current_config, BASE_PATH
from api.api_utils import get_current_time

main_bp = Blueprint("main", __name__)


@main_bp.route('/check_healthy', methods=['GET', 'POST'])
def check_healthy():
    result = {
        "status": "up",
        "time": get_current_time(),
        "project": "task_api",
        "version": current_config.VERSION
    }
    response = make_response(json.dumps(result))
    response.headers["Content-Type"] = "application/json;charset=utf-8"
    return response


@main_bp.route('/api_md', methods=['GET', 'POST'])
def api_md():
    result = []
    with open(os.path.join(BASE_PATH, 'api.MD'), encoding='utf8') as f:
        for line in f.readlines():
            result.append(line)
    response = make_response('\n<br>'.join(result))
    response.headers["Content-Type"] = "text/html; charset=utf-8"
    return response